MS-DOS API

The MS-DOS API is an API used originally in MS-DOS/PC-DOS, and later by other DOS systems. Most calls to the DOS API invoke software interrupt 21h (INT 21h). By calling INT 21h with a subfunction number in the AH processor register and other parameters in other registers, one invokes various DOS services. DOS services include keyboard input, video output, disk file access, executing programs, memory allocation, and various other things. The subfunctions provided in the first release of MS-DOS in 1981 were strongly oriented to compatibility with CP/M. A major revamp of the DOS API (partially influenced by certain Unix concepts) was undertaken for the release of MS-DOS 2.0 in 1983, adding numerous new subfunctions to deal with file I/O using abstract "handles" and support for subdirectories. In these new subfunctions, strings are usually terminated by a NUL byte (ASCIIZ). In MS-DOS version 3.1 (released in 1985), several subfunctions were added for dealing with networks. In MS-DOS version 4, calls were introduced to manage expanded memory according to the Lotus-Intel-Microsoft specification.

There are various implementations of the DOS API, including PC-DOS, MS-DOS, DR-DOS, FreeDOS, PTS-DOS, and others. The DOS API is based on the BIOS, and DOS routines often internally access BIOS interrupt calls.

DOS extenders along with the DOS Protected Mode Interface (DPMI) extend the DOS API to either 16-bit or 32-bit protected mode. The MS-DOS API is partially dependent on x86 code, hence DOS cannot be ported to other processor architectures.

Contents

The MS-DOS API and Windows

Microsoft Windows versions 1.0 through 3.1 were graphical shells that ran on MS-DOS and relied on the MS-DOS API (though using its own API for Windows programs). Windows 9x was also DOS-based, but used a custom version of MS-DOS, mainly as a bootloader. It did not use the MS-DOS API much after booting. However, Windows 9x provided the DOS API to programs running within a command shell window. Earlier Windows 9x versions (at least through the first edition of Windows 98) also can be booted into plain CLI "DOS mode" with no GUI and no Windows system services, for running pure DOS programs. The Windows 9x DOS versions (numbered 7.0 and above) include several new service subfunctions for dealing with long filenames (LFNs).

Windows NT and the systems based on it (e.g. Windows XP and Windows Vista) are not based on MS-DOS, but use a virtual machine, NTVDM, to handle the DOS API. NTVDM works by running a DOS program in virtual 8086 mode (an emulation of real mode within protected mode available on 80386 and higher processors). DOSEMU for Linux uses a similar approach.

Common DOS services

Some basic INT 21h function calls present since DOS version 2.0:

Subfunction
(hex)
Service Parameters Returns
AH = 00 DOS 1+
Terminate program
Never [1]
AH = 01 DOS 1+
Read character from STDIN
AL=character read [2]
AH = 02 DOS 1+
Write character to STDOUT
DL=character [3]
AH = 09 DOS 1+
Write string to STDOUT
DS:DX=pointer to '$' terminated string [4]
AH = 3C DOS 2+
Create or truncate file
CX=file attributes ; DS:DX->ASCIIZ filename CF=1 on error ; AX=error code ; AX=file handle [5]
AH = 3D DOS 2+
Open existing file
AL=access and sharing modes ; DS:DX->ASCIIZ ; CL=attribute mask CF=1 on error ; AX=error code ; AX=file handle [6]
AH = 3F DOS 2+
Read from file or device
BX=file handle ; CX=bytes to read ; DS:DX->data CF=1 on error ; AX=error code or bytes read [7]
AH = 40 DOS 2+
Write to file or device
BX=file handle ; CX=bytes to write ; DS:DX->data CF=1 on error ; AX=error code or bytes written [8]
AH = 3E DOS 2+
Close file
BX=file handle CF=1 on error ; AX=error code [9]
AH = 42 DOS 2+
Set file position
AL=origin of move, 0-start, 1-current, 2-end ; BX=file handle ; CX:DX=(signed) offset CF=1 on error ; AX=error code ; DX:AX=position from beginning [10]

Operating systems with support for the MS-DOS API

Programs with support for the MS-DOS API

See also

References